package com.xtwy.controller;

import com.xtwy.common.core.entity.Result;
import com.xtwy.entity.User;
import com.xtwy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作 者: 侯建军
 * @日 期: 2018/7/28 12:26
 * @描 述: 用户服务接口
 * 请求地址：
 * 例：http://192.168.1.98:9020/user/findByUsername/123
 * 数据返回：{"code":200,"msg":"操作成功","data":{"username":"hjj","password":"123456"}}
 */
@RequestMapping("user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("findByUsername/{username}")
    public Result findByUsername(@PathVariable("username") String username) {
        User user = userService.findByUsername(username);
        if (user == null) {
            return Result.failure(100, "用户不存在");
        }
        //数据包装
        return Result.ok().setData(user);
    }
}
